// Copyright )1997 Easter-eggs. All Rights Reserved.

DefConst('kEETransferTransportName, "EETransfer");
DefConst('kEETransferTransportString, "Transfer:Eggs");
DefConst('kEETransferTransportSymbol, Intern(kEETransferTransportString));
DefConst('kEETransferClientSymbolsSymbol, Intern("clients:" & kEETransferTransportString));
DefConst('kEETransferScriptsSymbol, Intern("scripts:" & kEETransferTransportString));
DefConst('kEETransferVersionString, "1.0");

/*
	============================================================================
	Scripts constants
	============================================================================
*/

DefConst('RegEETransferScript, func(script)
		begin
			if not GlobalVarExists(kEETransferScriptsSymbol) then
				DefGlobalVar(kEETransferScriptsSymbol, {});
			GetGlobalVar(kEETransferScriptsSymbol).(EnsureInternal(script.symbol)) := script;
		end);

DefConst('UnRegEETransferScript, func(scriptSymbol)
		begin
			if GlobalVarExists(kEETransferScriptsSymbol) then
				begin
					local scripts := GetGlobalVar(kEETransferScriptsSymbol);
					if HasSlot(scripts, scriptSymbol) then
						begin
							RemoveSlot(scripts, scriptSymbol);
							if Length(scripts) = 0 then
								UnDefGlobalVar(kEETransferScriptsSymbol);
						end;
				end;
		end);

/*
	============================================================================
	Clients constants
	============================================================================
*/


DefConst('RegEETransferClient, func(symbol)
		begin
			if not GlobalVarExists(kEETransferClientSymbolsSymbol) then
				DefGlobalVar(kEETransferClientSymbolsSymbol, []);
			AddArraySlot(GetGlobalVar(kEETransferClientSymbolsSymbol), EnsureInternal(symbol));
			local config := GetUserConfig(kEETransferTransportSymbol);
			if not config then
				config := {};
			if not config.clientSymbol then
				begin
					config.clientSymbol := symbol;
					SetUserConfig(kEETransferTransportSymbol, config);
				end;
		end);

DefConst('SetEETransferClient, func(symbol)
		begin
			local config := GetUserConfig(kEETransferTransportSymbol);
			if not config then
				config := {};
			if config.clientSymbol <> symbol then
				begin
					config.clientSymbol := symbol;
					SetUserConfig(kEETransferTransportSymbol, config);
				end;
		end);

DefConst('UnRegEETransferClient, func(symbol)
		begin
			if GlobalVarExists(kEETransferClientSymbolsSymbol) then
				begin
					local clientSymbols := GetGlobalVar(kEETransferClientSymbolsSymbol);
					local i := LSearch(clientSymbols, symbol, 0, '|=|, nil);
					if i then
						begin
							RemoveSlot(clientSymbols, i);
							if Length(clientSymbols) = 0 then
								UnDefGlobalVar(kEETransferClientSymbolsSymbol);
						end;
				end;
		end);

/*
	============================================================================
	SendZModem constants
	============================================================================
*/


/*
	----------------------------------------------------------------------------
	fileConversion option constants.
	----------------------------------------------------------------------------
*/

constant kFileConversion_NONE			:=	0x00;
		// No file conversion.

constant kFileConversion_ZCBIN			:=	0x01;
		// "Binary" transfer - inhibit conversion unconditionally.

constant kFileConversion_ZCNL			:=	0x02;
		// Convert received end of line to local end of line
		// convention. The supported end of line conventions are
		// CR/LF (most ASCII based operating systems except Unix
		// and Macintosh), and NL (Unix). Either of these two end
		// of line conventions meet the permissible ASCII
		// definitions for Carriage Return and Line Feed/New Line.
		// Neither the ASCII code nor ZMODEM ZCNL encompass lines
		// separated only by carriage returns. Other processing
		// appropriate to ASCII text files and the local operating
		// system may also be applied by the receiver (Filtering
		// RUBOUT, NULL, Ctrl-Z, etc).

constant kFileConversion_ZCRECOV			:=	0x03;
constant kFileConversion_ZCRESUM			:=	0x03;	// Un autre nom pour la mme chose
		// Recover/Resume interrupted file transfer. ZCREVOV is
		// also useful for updating a remote copy of a file that
		// grows without resending of old data. If the destination
		// file exists and is no longer than the source, append to
		// the destination file and start transfer at the offset
		// corresponding to the receiver's end of file. This
		// option does not apply if the source file is shorter.
		// Files that have been converted (e.g., ZCNL) or subject
		// to a single ended Transport Option cannot have their
		// transfers recovered.
		// (default value).


/*
	----------------------------------------------------------------------------
	fileManagement option constants.
	----------------------------------------------------------------------------
*/

constant kFileManagement_NONE			:=	0x00;
		// No file management (default value).

constant kFileManagement_ZMSKNOLOC	:= 0x80;
		// Instructs the receiver to bypass the current file if the receiver
		// does not have a file with the same name.
		// NB: this option can be ored with any of the following constants.

constant kFileManagement_ZMNEWL		:= 0x01;
		// Transfer file if destination file absent. Otherwise, transfer file
		// overwriting destination if the source file is newer or longer.
constant kFileManagement_ZMCRC		:= 0x02;
		// Compare the source and destination files. Transfer if file lengths
		// or file polynomials differ.
constant kFileManagement_ZMAPND		:= 0x03;
		// Append source file contents to the end of the existing destination
		// file (if any).
constant kFileManagement_ZMCLOB		:= 0x04;
		// Replace existing destination file (if any).
constant kFileManagement_ZMNEW		:= 0x05;
		// Transfer file if destination file absent. Otherwise, transfer file
		// overwriting destination if the source file is newer.
constant kFileManagement_ZMDIFF		:= 0x06;
		// Transfer file if destination file absent. Otherwise, transfer file
		// overwriting destination if files have different lengths or dates.
constant kFileManagement_ZMPROT		:= 0x07;
		// Protect destination file by transferring file only if the
		// destination file is absent.
